import Dayjs from 'dayjs';

export default {
    setProps(vm) {
        let para = {
            changeSeat: vm.form.changeSeat ? 1 : 0,
            ticketType: vm.ticketType,
            orderParams: {
				cinemaId: vm.cinemaModel.cinemaId,
                cinemaName: vm.cinemaModel.cinemaName,
				cinemaAddress: vm.cinemaModel.cinemaAddress,
                filmImg: vm.cinemaModel.imgUrl,
                showId: vm.cinemaModel.showId,
                seats: JSON.stringify(vm.seatsList),
                mobile: vm.form.mobile,
                changeSeat: vm.form.changeSeat ? 1 : 0,
                // salePrice: vm.seatsPrice,
            },
        };

        return para;
    },
    checkForm(vm) {
        return new Promise(async resolve => {
            let isPhone = this.isPhoneCheck(vm.form.mobile);
            if (isPhone) {
                await this.isModelCheck(vm);
            }
            resolve(isPhone);
        });
    },
    isPhoneCheck(e) {
        if (!e) {
            uni.showToast({ title: '请输入手机号', icon: 'none' });
            return false;
        }
        let reg = /^1[3456789]\d{9}$/;
        if (!reg.test(e)) {
            uni.showToast({ title: '请输入正确手机号', icon: 'none' });
            return false;
        }
        return true;
    },
    isModelCheck(vm) {
        return new Promise(resolve => {
            if (vm.form.changeSeat) {
                return resolve(true);
            }
            vm.$refs.modal.$showModal({
                content: '若选择关闭“自动换座”，则在您选择的座位被占时，系统将会自动退款此订单，出票率非常低。为了节省您的购票时间，建议开启“自动换座”开关，我们会根据实际情况为您匹配最佳的观影座位。',
                confirmText: '自动换座',
                cancelText: '不开启',
                success: res => {
                    vm.$refs.modal.$hideModal();
                    vm.form.changeSeat = res.confirm ? true : false;
                    getApp().globalData.subcontracting_movie.isAutoSeat = vm.form.changeSeat;
                    resolve(true);
                },
            });
        });
    },
    isPreferTicket(e) {
        if (e.startTime) {
            let nowDate = Dayjs().valueOf();
            let startDate = Dayjs(e.startTime).valueOf();
            return startDate > nowDate + 5400000;
        }
        return true;
    },
};
